<?php

/**
 * 清单广场-达人清单池（每天1点更新一次）
 */

ini_set('display_errors', 1);
ini_set('memory_limit', -1);
ini_set("error_reporting", E_ALL ^ E_NOTICE);

require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\cache\album\AlbumSquarePool;
use Biz\model\Album\AlbumListModel;
use Doraemon\model\McnUser;
use Doraemon\model\McnUserExtendInfo;
use hhz\constant\redis\redisKeys;
use Hhz\Redis\newCache;

$mcnUids = McnUser::selectByWhere([
    'level' => McnUser::MCN_LIST,
    'status' => McnUser::STATUS_NORMAL
], "uid");
$mcnInfos = McnUserExtendInfo::selectByWhere([
    'uid' => $mcnUids,
    'personal_preference[!]' => ''
], ['uid', 'personal_preference']);
$uids = [];
foreach ($mcnInfos as $row) {
    if (!empty($row['personal_preference'])) {
        $uids[] = $row['uid'];
    }
}
var_dump('达人uid:' . json_encode($uids));
$albumList = AlbumListModel::selectByWhere([
    'uid' => $uids,
    'quality' => [
        AlbumListModel::QUALITY_GOOD, AlbumListModel::QUALITY_EXCELLENT
    ],
    'status' => AlbumListModel::STATS_LIST_PUBLIC_SHOW_MAP
]);
$userAlbumList = [];
foreach ($albumList as $row) {
    $userAlbumList[$row['uid']][] = $row['album_id'];
}
$daRenAlbumUids = [];
foreach ($userAlbumList as $uid => $albumIds) {
    if (count($albumIds) >= 3) {
        $daRenAlbumUids[] = $uid;
    }
}
var_dump('符合条件的达人uid：' . json_encode($daRenAlbumUids));

if ($daRenAlbumUids) {
    $newRedis = new newCache(redisKeys::KEY_B_CACHE_ALBUM_SQUARE_DAREN_POOL);
    $newRedis->setCache(implode(',', $daRenAlbumUids));
}